using System.Linq;
using Magiq.Behaviors;
using Magiq.Query;

namespace Magiq.Objects
{
    public class QueryStrategy<T> : BehaviorHandler<IObjectsQueryBehavior>, IQueryStrategy<T>
    {
        private readonly IQuery<T> query;

        public QueryStrategy(IQuery<T> query) : base(query.Behavior)
        {
            this.query = query;
            Default<DefaultObjectsBehavior>();
        }

        public IQueryable<T> Execute()
        {
            return Call(x => x.GetQueryableFrom(query.Source));
        }
    }
}